import os
import shutil

def copy_files(txt_file, path_a, path_b):
    # 读取文件名
    with open(txt_file, 'r') as f:
        file_names = [line.strip() for line in f.readlines()]

    # 确保目标路径存在
    os.makedirs(path_b, exist_ok=True)

    # 遍历文件名，复制文件
    for file_name in file_names:
        file_path_a = os.path.join(path_a, file_name)
        file_path_b = os.path.join(path_b, file_name)

        # 检查文件是否存在
        if os.path.exists(file_path_a):
            # shutil.copy(file_path_a, file_path_b)
            shutil.move(file_path_a, file_path_b)
            print(f"已复制: {file_name}")
        else:
            print(f"文件未找到: {file_name}")

# 示例使用
txt_file = "not_exist_file.txt"  # txt文件路径
path_a = "/home/champrin/Desktop/record_data/网盘/兵种内录/装甲板数据集/2023-联盟赛前/22dataset/DATA5900/labels"  # 原路径
path_b = "/home/champrin/Desktop/record_data/网盘/兵种内录/装甲板数据集/2023-联盟赛前/22dataset/DATA5900/images_not_exist_in_image_"  # 目标路径

copy_files(txt_file, path_a, path_b)
